package com.app.controller;


import com.app.model.UserModel;
import com.app.service.ShareLikesComService;
import com.app.service.UserService;
import com.app.util.Result;
import com.app.util.TokenUtils;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@Controller
@RestController
@Data
public class ShareLikesComController {


    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    ShareLikesComService shareLikesComService;
    @Autowired
    UserService userService;
    //新增
    @PostMapping("/insertLikes")
    public Result<Object> insertLikes(int type, int circleId, String comments, HttpServletRequest request) {
        return Result.success(shareLikesComService.insertLikes(type,circleId,comments,request));
    }
    //删除
    @PostMapping("/delLikeAndCom")
    public Result<Object> delLikeAndCom(int circleId, int type, HttpServletRequest request){
        return Result.success(shareLikesComService.delLikeAndCom(circleId,type,request));
    }
    @PostMapping("/delCom")
    public Result<Object> delCom(int id, HttpServletRequest request){
        String token = request.getHeader("token");
        if(token==null)
        {
            return Result.error(405, "token不存在");

        }
        TokenUtils tokenUtil = new TokenUtils();
        String mobile = tokenUtil.verify(token);
        if (mobile.equals("false")){
            return null;
        }
        UserModel user = userService.getUserByMobile(mobile);
        return Result.success(shareLikesComService.delCom(id));
    }


}
